import grid.gridClient.Plouffe_Bellard;
import java.util.*;
import java.io.*;

class TestPB
{
	public static void main(String[] args)
	{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String Pi = "3.";
		int startPos = 0, range = 0;
		try
		{
			System.out.print("The start position of Pi: ");
			String pos = br.readLine();
			if(pos.length()==0)
			{
				startPos = 1;
			}
			else
			{
				startPos = Integer.parseInt(pos);
			}
			System.out.print("The range of computing: ");
			range = Integer.parseInt(br.readLine());
		}
		catch(IOException ioe){}
		Plouffe_Bellard PB = new Plouffe_Bellard();
		Date startDate = new Date();
		Date endDate = new Date();
		System.out.println("Start position: "+startPos);
		System.out.println("Computing range: "+range);
		startDate.setTime(System.currentTimeMillis());
		System.out.println("Start: " + startDate);
		System.out.println("Computing");
		for (int i = startPos; i<(startPos+range); i=i+9)
		{
			System.out.print(PB.CalculatePiDigits(i));
			Pi = Pi+PB.CalculatePiDigits(i);
		}
		endDate.setTime(System.currentTimeMillis());
		System.out.println("\nPi="+Pi);
		System.out.println("\nEnd: " + endDate);
		long spanSeconds = (endDate.getTime() - startDate.getTime())/1000;
		System.out.println("Spends " + spanSeconds + " Seconds.");
/**/	try
		{
			System.out.println("Press Enter to continue...");
			System.in.read();
		}
		catch (Exception ex){};
	}
}
